var waterPollutionController = WaterPollutionController();
var gasPollutionController = GasPollutionController();
var monitorPointController = MonitorPointController();
var monitorTable = '#monitorTable';
var monitorTableGas = '#monitorTableGas';
var pageNumber = null;

var chartStartTime=undefined,chartEndTime=undefined,sheetStartTime=undefined,sheetEndTime=undefined;

function WaterPollutionService() {
    var service = {};

    //加载四个趋势图
    service.load = function (monitorPointId) {
        waterPollutionController.getPollutionRtdRecordsToday(monitorPointId,function (resp) {
            //2为污水监测
            var data = [];
            for(var i=0;i<=9;i++){
                data.push(resp.data[i])
            };
            //console.log(common.dateFormatter_hyphen(resp.data[100].collectTime));
            service.loadPhChart(data);
            service.loadNiChart(data);
            service.loadCrChart(data);
            service.loadSewageChart(data);
        })
    };

    service.loadPhChart = function (data) {
        var x=[],y=[];
        data.map(function (item) {
            var time = common.dateFormatter_hyphen(item.collectTime);
            x.push(time.slice(11,16));
            y.push(item.ph);
        });

        x=x.reverse();
        y=y.reverse();
        $("#phNewest").html('最新浓度:'+y[9]);
        var phDom = document.getElementById("phChart");
        var phChart = echarts.init(phDom);
        var phOption = {
            tooltip : {
                trigger: 'axis',
                axisPointer: {
                    type: 'line',
                    label: {
                        backgroundColor: '#6a7985'
                    }
                }
            },
            xAxis: {
                type: 'category',
                data: x,
                axisLine:{
                    lineStyle:{
                        color:'#062b3d',
                    }
                },
                axisLabel:{
                    color:'#22b9e9'
                },
            },
            yAxis: {
                type: 'value',
                name: '',
                scale: true,
                nameTextStyle:{
                    color:'#22b9e9',
                    fontWeight:'bold',
                    verticalAlign:'center'
                },
                axisLine:{
                    lineStyle:{
                        color:'#062b3d',
                    }
                },
                axisLabel:{
                    color:'#22b9e9',
                    fontWeight:'bold'
                },
                splitLine: {
                    show: true,
                    lineStyle:{
                        color: ['#062b3d'],
                    }
                }
            },
            series: [{
                symbol: "none",
                data: y,
                type: 'line',
                itemStyle : {
                    normal : {
                        color:'#22b9e9',
                        lineStyle:{
                            color:'#22b9e9'
                        }
                    }
                },
            }],
            legend: {
                x: 'left'
            },
            grid:[{
                top:'20%',
                bottom:'20%'
            }]
        };
        phChart.setOption(phOption, true);
    };

    service.loadCrChart = function (data) {
        var x=[],y=[];
        data.map(function (item) {
            var time = common.dateFormatter_hyphen(item.collectTime);
            x.push(time.slice(11,16));
            y.push(item.chromium);
        });

        x=x.reverse();
        y=y.reverse();
        $("#crNewest").html('最新浓度:'+y[9]+' 毫克/升');
        var crDom = document.getElementById("crChart");
        var crChart = echarts.init(crDom);
        var crOption = {
            tooltip : {
                trigger: 'axis',
                axisPointer: {
                    type: 'line',
                    label: {
                        backgroundColor: '#6a7985'
                    }
                }
            },
            xAxis: {
                type: 'category',
                data: x,
                axisLine:{
                    lineStyle:{
                        color:'#062b3d',
                    }
                },
                axisLabel:{
                    color:'#22b9e9'
                },
            },
            yAxis: {
                type: 'value',
                name: '浓度：毫克/升',
                scale: true,
                nameTextStyle:{
                    color:'#22b9e9',
                    fontWeight:'bold',
                    verticalAlign:'center'
                },
                axisLine:{
                    lineStyle:{
                        color:'#062b3d',
                    }
                },
                axisLabel:{
                    color:'#22b9e9',
                    fontWeight:'bold'
                },
                splitLine: {
                    show: true,
                    lineStyle:{
                        color: ['#062b3d'],
                    }
                }
            },
            series: [{
                symbol: "none",
                data:y,
                type: 'line',
                itemStyle : {
                    normal : {
                        color:'#22b9e9',
                        lineStyle:{
                            color:'#22b9e9'
                        }
                    }
                },
            }],
            legend: {
                x: 'left'
            },
            grid:[{
                top:'20%',
                bottom:'20%'
            }]
        };
        crChart.setOption(crOption, true);
    };

    service.loadNiChart = function (data) {
        var x=[],y=[];
        data.map(function (item) {
            var time = common.dateFormatter_hyphen(item.collectTime);
            x.push(time.slice(11,16));
            y.push(item.nickel);
        });

        x=x.reverse();
        y=y.reverse();
        $("#niNewest").html('最新浓度:'+y[9]+' 毫克/升');
        var niDom = document.getElementById("niChart");
        var niChart = echarts.init(niDom);
        var niOption = {
            tooltip : {
                trigger: 'axis',
                axisPointer: {
                    type: 'line',
                    label: {
                        backgroundColor: '#6a7985'
                    }
                }
            },
            xAxis: {
                type: 'category',
                data: x,
                axisLine:{
                    lineStyle:{
                        color:'#062b3d',
                    }
                },
                axisLabel:{
                    color:'#22b9e9'
                },
            },
            yAxis: {
                type: 'value',
                name: '浓度：毫克/升',
                scale: true,
                nameTextStyle:{
                    color:'#22b9e9',
                    fontWeight:'bold',
                    verticalAlign:'center'
                },
                axisLine:{
                    lineStyle:{
                        color:'#062b3d',
                    }
                },
                axisLabel:{
                    color:'#22b9e9',
                    fontWeight:'bold'
                },
                splitLine: {
                    show: true,
                    lineStyle:{
                        color: ['#062b3d'],
                    }
                }
            },
            series: [{
                symbol: "none",
                data: y,
                type: 'line',
                itemStyle : {
                    normal : {
                        color:'#22b9e9',
                        lineStyle:{
                            color:'#22b9e9'
                        }
                    }
                },
            }],
            legend: {
                x: 'left'
            },
            grid:[{
                top:'20%',
                bottom:'20%'
            }]
        };
        niChart.setOption(niOption, true);
    };

    service.loadSewageChart = function (data) {
        var x=[],y=[];
        data.map(function (item) {
            var time = common.dateFormatter_hyphen(item.collectTime);
            x.push(time.slice(11,16));
            y.push(item.sewage);
        });
        x=x.reverse();
        y=y.reverse();
        $("#sewageNewest").html('最新流速:'+y[9]+' 升/秒');
        var pointSpeedDom = document.getElementById("pointSpeedChart");
        var pointSpeedChart = echarts.init(pointSpeedDom);
        var pointSpeedOption = {
            tooltip : {
                trigger: 'axis',
                axisPointer: {
                    type: 'line',
                    label: {
                        backgroundColor: '#6a7985'
                    }
                }
            },
            xAxis: {
                type: 'category',
                data: x,
                axisLine:{
                    lineStyle:{
                        color:'#062b3d',
                    }
                },
                axisLabel:{
                    color:'#22b9e9'
                },
            },
            yAxis: {
                type: 'value',
                name: '流速：升/秒',
                scale: true,
                nameTextStyle:{
                    color:'#22b9e9',
                    fontWeight:'bold',
                    verticalAlign:'center'
                },
                axisLine:{
                    lineStyle:{
                        color:'#062b3d',
                    }
                },
                axisLabel:{
                    color:'#22b9e9',
                    fontWeight:'bold'
                },
                splitLine: {
                    show: true,
                    lineStyle:{
                        color: ['#062b3d'],
                    }
                }
            },
            series: [{
                symbol: "none",
                data: y,
                type: 'line',
                itemStyle : {
                    normal : {
                        color:'#22b9e9',
                        lineStyle:{
                            color:'#22b9e9'
                        }
                    }
                },
            }],
            legend: {
                x: 'left'
            },
            grid:[{
                top:'20%',
                bottom:'20%'
            }]
        };
        pointSpeedChart.setOption(pointSpeedOption, true);
    };

    //获取今天的0点是23:59时间
    service.getTodayTime = function () {
        var start = new Date(new Date(new Date().toLocaleDateString()).getTime());
        var end = new Date() ;
        return {start:start,end:end};
    };

    //获取load加载所需要的所有参数
    service.getParameterChart = function () {
        var startTime = common.dateFormatter_inverse($("#chartStartTime").val());
        var endTime = common.dateFormatter_inverse($("#chartEndTime").val());
        var dataType = $("#chartDataType").val();
        return {
            startTime:startTime,
            endTime:endTime,
            dataType:dataType,
        }
    };

    //加载radio表格
    service.loadRadioChart = function (monitorPointId,startTime,endTime,dataType,radioFlag) {
        monitorPointController.getMonitorPointBaseInfoById(monitorPointId,function (resp) {
            var upperData = resp.data.thresholdConfigs
            //1ph 2ni 3cr
            waterPollutionController.getPollutionIntervalRecordsForChart(monitorPointId,startTime,endTime,dataType,function (resp) {
                var x=[],y=[];
                switch (radioFlag) {
                    case 'ph':
                        resp.data.phs.map(function (item) {
                            x.push(common.dateFormatter_hyphen(item.time));
                            y.push(item.value);
                        });
                        service.loadRadioChartData(x,y,'ph',upperData[0].alarmUpperLimit);
                        break;
                    case 'cr':
                        resp.data.chromiums.map(function (item) {
                            x.push(common.dateFormatter_hyphen(item.time));
                            y.push(item.value);
                        });
                        service.loadRadioChartData(x,y,'cr',upperData[2].alarmUpperLimit);
                        break;
                    case 'ni':
                        resp.data.nickels.map(function (item) {
                            x.push(common.dateFormatter_hyphen(item.time));
                            y.push(item.value);
                        });
                        service.loadRadioChartData(x,y,'ni',upperData[1].alarmUpperLimit);
                        break;
                    case 'sewage':
                        resp.data.sewages.map(function (item) {
                            x.push(common.dateFormatter_hyphen(item.time));
                            y.push(item.value);
                        });
                        service.loadRadioChartData(x,y,'sewage','');
                        break;
                }

            })
        })
    };

    //加载radio图标数据
    service.loadRadioChartData = function (x,y,flag,upper) {
        var t= '浓度：毫克/升';
        if(flag === 'sewage'){
            t = '排放量：吨';
        }
        if(flag === 'ph'){
            t = '';
        }
        var centerChartdom = document.getElementById("centerChart");
        var centerChart = echarts.init(centerChartdom);
        var centerChartoption;
        if(flag === 'sewage'){
            centerChartoption = {
                tooltip : {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'line',
                        label: {
                            backgroundColor: '#6a7985'
                        }
                    }
                },
                xAxis: {
                    type: 'category',
                    data: x.reverse(),
                    axisLine:{
                        lineStyle:{
                            color:'#062b3d',
                        }
                    },
                    axisLabel:{
                        color:'#22b9e9'
                    },
                },
                yAxis: {
                    type: 'value',
                    name: t,
                    scale: true,
                    nameTextStyle:{
                        color:'#22b9e9',
                        fontWeight:'bold',
                        verticalAlign:'center'
                    },
                    axisLine:{
                        lineStyle:{
                            color:'#062b3d',
                        },

                    },
                    axisLabel:{
                        color:'#22b9e9',
                        fontWeight:'bold'
                    },
                    splitLine: {
                        show: true,
                        lineStyle:{
                            color: ['#062b3d'],
                        }
                    }
                },
                series: [{
                    symbol: "none",
                    data:y.reverse(),
                    type: 'line',
                    itemStyle : {
                        normal : {
                            color:'#22b9e9',
                            lineStyle:{
                                color:'#22b9e9'
                            }
                        }
                    },
                    areaStyle: {
                        color:{
                            type: 'linear',
                            x: 0,
                            y: 0,
                            x2: 0,
                            y2: 1,
                            colorStops: [{
                                offset: 0, color: '#12b680' // 0% 处的颜色
                            }, {
                                offset: 1, color: '#0a1930' // 100% 处的颜色
                            }],
                            global: false // 缺省为 false
                        }
                    }
                }],
                legend: {
                    x: 'left'
                },
            };
        }
        else{
            centerChartoption = {
                tooltip : {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'line',
                        label: {
                            backgroundColor: '#6a7985'
                        }
                    }
                },
                xAxis: {
                    type: 'category',
                    data: x.reverse(),
                    axisLine:{
                        lineStyle:{
                            color:'#062b3d',
                        }
                    },
                    axisLabel:{
                        color:'#22b9e9'
                    },
                },
                yAxis: {
                    type: 'value',
                    name: t,
                    scale: true,
                    nameTextStyle:{
                        color:'#22b9e9',
                        fontWeight:'bold',
                        verticalAlign:'center'
                    },
                    axisLine:{
                        lineStyle:{
                            color:'#062b3d',
                        },

                    },
                    axisLabel:{
                        color:'#22b9e9',
                        fontWeight:'bold'
                    },
                    splitLine: {
                        show: true,
                        lineStyle:{
                            color: ['#062b3d'],
                        }
                    }
                },
                series: [{
                    symbol: "none",
                    data:y.reverse(),
                    // markLine:{
                    //     data: [
                    //         [
                    //             { name: '', xAxis: x[0], yAxis: upper, symbol: 'none',label:{formatter: '阈值上限:'+upper}},
                    //             { name: '', xAxis: x[x.length-1], yAxis: upper, symbol: 'none' },
                    //         ],
                    //     ],
                    // },
                    type: 'line',
                    itemStyle : {
                        normal : {
                            color:'#22b9e9',
                            lineStyle:{
                                color:'#22b9e9'
                            }
                        }
                    },
                    areaStyle: {
                        color:{
                            type: 'linear',
                            x: 0,
                            y: 0,
                            x2: 0,
                            y2: 1,
                            colorStops: [{
                                offset: 0, color: '#12b680' // 0% 处的颜色
                            }, {
                                offset: 1, color: '#0a1930' // 100% 处的颜色
                            }],
                            global: false // 缺省为 false
                        }
                    }
                }],
                legend: {
                    x: 'left'
                },
            };
        }
        centerChart.setOption(centerChartoption, true);
    };

    return service;
}

var waterPollutionService = WaterPollutionService();

function RealTimeGasService() {
    var service = {};

    service.load = function (monitorPointId) {
        gasPollutionController.getPollutionRtdRecordsToday(monitorPointId,function (resp) {
            var data = [];
            for(var i=0;i<=599;i++){
                data.push(resp.data[i])
            };
            service.loadVOCChart(data);
            service.loadTolueneChart(data);
        });
    };
    //加载VOC数据
    service.loadVOCChart = function (data) {
        var x=[],y=[];
        data.map(function (item) {
            var time = common.dateFormatter_hyphen(item.collectTime);
            x.push(time.slice(11,19));
            y.push(item.voc);
        });
        x=x.reverse();
        y=y.reverse();
        $("#phNewest").html('最新浓度:'+y[599]+' PPM');
        var phDom = document.getElementById("phChart");
        var phChart = echarts.init(phDom);
        var phOption = {
            tooltip : {
                trigger: 'axis',
                axisPointer: {
                    type: 'line',
                    label: {
                        backgroundColor: '#6a7985'
                    }
                }
            },
            xAxis: {
                type: 'category',
                data: x,
                axisLine:{
                    lineStyle:{
                        color:'#062b3d',
                    }
                },
                axisLabel:{
                    color:'#22b9e9'
                },
            },
            yAxis: {
                type: 'value',
                name: '单位：PPM',
                scale: true,
                nameTextStyle:{
                    color:'#22b9e9',
                    fontWeight:'bold',
                    verticalAlign:'center'
                },
                axisLine:{
                    lineStyle:{
                        color:'#062b3d',
                    }
                },
                axisLabel:{
                    color:'#22b9e9',
                    fontWeight:'bold'
                },
                splitLine: {
                    show: true,
                    lineStyle:{
                        color: ['#062b3d'],
                    }
                }
            },
            series: [{
                // symbol: "none",
                data: y,
                type: 'line',
                smooth: true,
                itemStyle : {
                    normal : {
                        color:'#22b9e9',
                        lineStyle:{
                            color:'#22b9e9'
                        }
                    }
                },
            }],
            legend: {
                x: 'left'
            },
            grid:[{
                top:'20%',
                bottom:'20%'
            }]
        };
        phChart.setOption(phOption, true);
    };
    //加载甲苯数据
    service.loadTolueneChart = function (data) {
        var x=[],y=[];
        data.map(function (item) {
            var time = common.dateFormatter_hyphen(item.collectTime);
            x.push(time.slice(11,19));
            y.push(item.toluene);
        });
        x=x.reverse();
        y=y.reverse();
        $("#crNewest").html('最新浓度:'+y[599]+' PPM');
        var crDom = document.getElementById("crChart");
        var crChart = echarts.init(crDom);
        var crOption = {
            tooltip : {
                trigger: 'axis',
                axisPointer: {
                    type: 'line',
                    label: {
                        backgroundColor: '#6a7985'
                    }
                }
            },
            xAxis: {
                type: 'category',
                data: x,
                axisLine:{
                    lineStyle:{
                        color:'#062b3d',
                    }
                },
                axisLabel:{
                    color:'#22b9e9'
                },
            },
            yAxis: {
                type: 'value',
                name: '单位：PPM',
                scale: true,
                nameTextStyle:{
                    color:'#22b9e9',
                    fontWeight:'bold',
                    verticalAlign:'center'
                },
                axisLine:{
                    lineStyle:{
                        color:'#062b3d',
                    }
                },
                axisLabel:{
                    color:'#22b9e9',
                    fontWeight:'bold'
                },
                splitLine: {
                    show: true,
                    lineStyle:{
                        color: ['#062b3d'],
                    }
                }
            },
            series: [{
                // symbol: "none",
                data:y,
                type: 'line',
                smooth: true,
                itemStyle : {
                    normal : {
                        color:'#22b9e9',
                        lineStyle:{
                            color:'#22b9e9'
                        }
                    }
                },
            }],
            legend: {
                x: 'left'
            },
            grid:[{
                top:'20%',
                bottom:'20%'
            }]
        };
        crChart.setOption(crOption, true);
    };

    //获取今天的0点到23:59时间
    service.getTodayTime = function () {
        // var start = common.dateFormatter_hyphen(new Date()-1000*60*10);
        var start = new Date(new Date(new Date().toLocaleDateString()).getTime());
        var end = new Date() ;
        return {start:start,end:end};
    };

    //获取load加载所需要的所有参数
    service.getParameterChart = function () {
        var startTime = common.dateFormatter_inverse($("#chartStartTime").val());
        var endTime = common.dateFormatter_inverse($("#chartEndTime").val());
        var dataType = $("#chartDataType").val();
        return {
            startTime:startTime,
            endTime:endTime,
            dataType:dataType,
        }
    };

    //加载radio表格
    service.loadRadioChart = function (monitorPointId,startTime,endTime,dataType,radioFlag) {
       monitorPointController.getMonitorPointBaseInfoById(monitorPointId,function (resp) {
           var upperData = resp.data.thresholdConfigs
           gasPollutionController.getPollutionRtdRecordsForChart(monitorPointId,startTime,endTime,function (resp) {
               var x=[],y=[];
               switch (radioFlag) {
                   case 'voc':
                       resp.data.vocs.map(function (item) {
                           x.push(common.dateFormatter_hyphen(item.time));
                           y.push(item.value);
                       });
                       $("#pointRadio").attr('checked','checked');
                       service.loadRadioChartData(x,y,upperData[1].alarmUpperLimit);
                       break;
                   case 'toluene':
                       resp.data.toluenes.map(function (item) {
                           x.push(common.dateFormatter_hyphen(item.time));
                           y.push(item.value);
                       });
                       $("#phRadio").attr('checked','checked');
                       service.loadRadioChartData(x,y,upperData[0].alarmUpperLimit);
                       break;
               }
           });
       });
    };

    //加载radio图标数据
    service.loadRadioChartData = function (x,y,upper) {

        var centerChartdom = document.getElementById("centerChart");
        var centerChart = echarts.init(centerChartdom);
        var centerChartoption = {
            tooltip : {
                trigger: 'axis',
                axisPointer: {
                    type: 'line',
                    label: {
                        backgroundColor: '#6a7985'
                    }
                }
            },
            xAxis: {
                type: 'category',
                data: x.reverse(),
                axisLine:{
                    lineStyle:{
                        color:'#062b3d',
                    }
                },
                axisLabel:{
                    color:'#22b9e9'
                },
            },
            yAxis: {
                type: 'value',
                name: '单位：PPM',
                scale: true,
                nameTextStyle:{
                    color:'#22b9e9',
                    fontWeight:'bold',
                    verticalAlign:'center'
                },
                axisLine:{
                    lineStyle:{
                        color:'#062b3d',
                    }
                },
                axisLabel:{
                    color:'#22b9e9',
                    fontWeight:'bold'
                },
                splitLine: {
                    show: true,
                    lineStyle:{
                        color: ['#062b3d'],
                    }
                }
            },
            series: [{
                symbol: "none",
                data:y.reverse(),
                markLine:{
                    data: [
                        [
                            { name: '', xAxis: x[0], yAxis: upper, symbol: 'none',label:{formatter: '阈值上限:'+upper}},
                            { name: '', xAxis: x[x.length-1], yAxis: upper, symbol: 'none' },
                        ],
                    ],
                },
                type: 'line',
                itemStyle : {
                    normal : {
                        color:'#22b9e9',
                        lineStyle:{
                            color:'#22b9e9'
                        }
                    }
                },
                areaStyle: {
                    color:{
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 0,
                        y2: 1,
                        colorStops: [{
                            offset: 0, color: '#12b680' // 0% 处的颜色
                        }, {
                            offset: 1, color: '#0a1930' // 100% 处的颜色
                        }],
                        global: false // 缺省为 false
                    }
                }
            }],
            legend: {
                x: 'left'
            },
        };
        centerChart.setOption(centerChartoption, true);
    };
    return service;
}

var realTimeGasService = RealTimeGasService();

function MonitorService() {
    var service = {};
    //数据的加载
    service.load = function (monitorPointId) {
        var para = service.getParameter();
        //console.log(para);
        waterPollutionController.getPollutionIntervalRecords(monitorPointId,1,para.pageSize,para.startTime,para.endTime,para.alarmFlag,para.dataType,function (resp) {
            var data = resp.data;
            service.loadTableData(data);
            var total = resp.extra;
            if(total === 0 ){
                total = 1;
            }
            $("#pageTool").jqPaginator({
                totalPages: Math.ceil(total / para.pageSize),
                visiblePages: 1,
                currentPage: 1,
                prev: '<li><a href="javascript:void(0);" style="background-color: #060f1f"><img src="../../common/images/left.png" style="position: relative;top: 6px;"><\/a><\/li>',
                next: '<li><a href="javascript:void(0);" style="background-color: #060f1f"><img src="../../common/images/right.png" style="position: relative;top: 6px;"><\/a><\/li>',
                page: '<li><a href="javascript:void(0);" style="margin-left:5px;margin-right:5px;background-color: #060f1f"> {{page}} / {{totalPages}} <\/a><\/li>',
                onPageChange: function (pageNo) {
                    pageNumber = pageNo;
                    $(monitorTable+" tr:not(:first)").empty("");
                    var p = service.getParameter();
                    waterPollutionController.getPollutionIntervalRecords(monitorPointId,pageNo,p.pageSize,p.startTime,p.endTime,p.alarmFlag,p.dataType,function (resp) {
                        service.loadTableData(resp.data);
                    });
                }
            });
        });
    };
    //数据表格的加载
    service.loadTableData = function(tableData){
        tableData.map(function (item,index) {
            //增加颜色的判断，加入td单元格的背景颜色
            var recordDataType = service.getParameter().dataType;
            var $trTemp = $("<tr></tr>");
            $trTemp.append("<td style='width: 20%'>"+ common.dateFormatter_hyphen(item.collectTime) +"</td>");
            //dataItemName(nickel,chromium,ph,sewage ),recordDataType,recordId,,
            $trTemp.append("<td style='width: 20%' onclick=openPopup("+"'sewage'"+",'"+recordDataType+"'"+",'"+item.id+"'"+")>"+ item.sewageCou +"</td>");
            //0正常 1超标 2异常
            //chromiumAvgAlarmFlag phAvgAlarmFlag nickelAvgAlarmFlag
            switch (item.phAvgAlarmFlag ) {
                case 0:
                    $trTemp.append("<td style='width: 20%;' onclick=openPopup("+"'ph'"+",'"+recordDataType+"'"+",'"+item.id+"'"+")>"+ item.phAvg +"</td>");
                    break;
                case 1:
                    $trTemp.append("<td style='width: 20%;background-color: #f5a623;color: #0C0C0C' onclick=openPopup("+"'ph'"+",'"+recordDataType+"'"+",'"+item.id+"'"+")>"+ item.phAvg +"</td>");
                    break;
                case 2:
                    $trTemp.append("<td style='width: 20%;background-color: #d0021b;color: #0C0C0C' onclick=openPopup("+"'ph'"+",'"+recordDataType+"'"+",'"+item.id+"'"+")>"+ item.phAvg +"</td>");
                    break;
            }

            switch (item.chromiumAvgAlarmFlag ) {
                case 0:
                    $trTemp.append("<td style='width: 20%;' onclick=openPopup("+"'chromium'"+",'"+recordDataType+"'"+",'"+item.id+"'"+")>"+ item.chromiumAvg +"</td>");
                    break;
                case 1:
                    $trTemp.append("<td style='width: 20%;background-color: #f5a623;color: #0C0C0C' onclick=openPopup("+"'chromium'"+",'"+recordDataType+"'"+",'"+item.id+"'"+")>"+ item.chromiumAvg +"</td>");
                    break;
                case 2:
                    $trTemp.append("<td style='width: 20%;background-color: #d0021b;color: #0C0C0C' onclick=openPopup("+"'chromium'"+",'"+recordDataType+"'"+",'"+item.id+"'"+")>"+ item.chromiumAvg +"</td>");
                    break;
            }

            switch (item.nickelAvgAlarmFlag ) {
                case 0:
                    $trTemp.append("<td style='width: 20%;' onclick=openPopup("+"'nickel'"+",'"+recordDataType+"'"+",'"+item.id+"'"+")>"+ item.nickelAvg +"</td>");
                    break;
                case 1:
                    $trTemp.append("<td style='width: 20%;background-color: #f5a623;color: #0C0C0C' onclick=openPopup("+"'nickel'"+",'"+recordDataType+"'"+",'"+item.id+"'"+")>"+ item.nickelAvg +"</td>");
                    break;
                case 2:
                    $trTemp.append("<td style='width: 20%;background-color: #d0021b;color: #0C0C0C' onclick=openPopup("+"'nickel'"+",'"+recordDataType+"'"+",'"+item.id+"'"+")>"+ item.nickelAvg +"</td>");
                    break;
            }
            $trTemp.appendTo(monitorTable);
        });
    };

    //获取今天的0点是23:59时间
    service.getTodayTime = function () {
        var start = new Date(new Date(new Date().toLocaleDateString()).getTime());
        var end = new Date(new Date(new Date().toLocaleDateString()).getTime()+24*60*60*1000-1);
        return {start:start,end:end};
    };

    //获取load加载所需要的所有参数
    service.getParameter = function () {
        var alarmFlag = $("#sheetAlarmFlag").val();
        var startTime = common.dateFormatter_inverse($("#sheetStartTime").val());
        var endTime = common.dateFormatter_inverse($("#sheetEndTime").val());
        var dataType = $("#sheetDataType").val();
        var pageSize = $("#pageSize").val();
        return {
            alarmFlag:alarmFlag,
            startTime:startTime,
            endTime:endTime,
            dataType:dataType,
            pageSize:pageSize
        }
    };

    //隐藏所有的table
    service.hiddenAllTable = function () {
        $("#info").css('display','none');
        $("#phInfo").css('display','none');
        $("#NiInfo").css('display','none');
        $("#CrInfo").css('display','none');
    };

    //弹窗所需的详细数据项查询
    service.getDataItemDetail = function(dataItemName,recordDataType,recordId){
        waterPollutionController.getDataItemDetail(recordDataType,recordId,dataItemName,function (resp) {
            var data = resp.data;
            monitorService.hiddenAllTable();
            switch(dataItemName)
            {
                case 'sewage':
                    $("#info").css('display','block');
                    service.loadInfoPopup(data);
                    break;
                case 'ph':
                    $("#phInfo").css('display','block');
                    service.loadPhPopup(data);
                    break;
                case 'chromium':
                    $("#CrInfo").css('display','block');
                    service.loadCrPopup(data);
                    break;
                case 'nickel':
                    $("#NiInfo").css('display','block');
                    service.loadNiPopup(data);
                    break;
            }
        })
    };

    //加载info弹窗
    service.loadInfoPopup = function (data) {
        //console.log(data);
        $("#infoMonitorPointName").html(data.monitorPointName);
        $("#infoCollectTime").html(common.dateFormatter_hyphen(data.collectTime));
        $("#infoAvg").html(data.avg);
        $("#infoMax").html(data.max);
        $("#infoMin").html(data.min);
        $("#infoAvg").html(data.min);
        $("#infoCou").html(data.cou);
    };

    //加载ph弹窗
    service.loadPhPopup = function (data) {
        //console.log(data)
        $("#phMonitorPointName").html(data.monitorPointName);
        $("#phCollectTime").html(common.dateFormatter_hyphen(data.collectTime));
        $("#phAvg").html(data.avg);
        $("#phMax").html(data.max);
        $("#phMin").html(data.min);
        $("#phAvg").html(data.avg);
        var alarm = data.thresholdConfig.alarmLowerLimit+'-'+data.thresholdConfig.alarmUpperLimit;
        var normal = data.thresholdConfig.normalValueLowerLimit+'-'+data.thresholdConfig.normalValueUpperLimit;
        $("#phAlarmLimit").html(alarm);
        $("#phNormalLimit").html(normal);

    };

    //加载ni弹窗
    service.loadNiPopup = function (data) {
        //console.log(data);
        $("#niMonitorPointName").html(data.monitorPointName);
        $("#niCollectTime").html(common.dateFormatter_hyphen(data.collectTime));
        $("#niAvg").html(data.avg);
        $("#niMax").html(data.max);
        $("#niMin").html(data.min);
        $("#niCou").html(data.cou);
        var alarm = data.thresholdConfig.alarmLowerLimit+'-'+data.thresholdConfig.alarmUpperLimit;
        var normal = data.thresholdConfig.normalValueLowerLimit+'-'+data.thresholdConfig.normalValueUpperLimit;
        $("#niAlarmLimit").html(alarm);
        $("#niNormalLimit").html(normal);
    };

    //加载cr弹窗
    service.loadCrPopup = function (data) {
        //console.log(data);
        $("#crMonitorPointName").html(data.monitorPointName);
        $("#crCollectTime").html(common.dateFormatter_hyphen(data.collectTime));
        $("#crAvg").html(data.avg);
        $("#crMax").html(data.max);
        $("#crMin").html(data.min);
        $("#crCou").html(data.cou);
        var alarm = data.thresholdConfig.alarmLowerLimit+'-'+data.thresholdConfig.alarmUpperLimit;
        var normal = data.thresholdConfig.normalValueLowerLimit+'-'+data.thresholdConfig.normalValueUpperLimit;
        $("#crAlarmLimit").html(alarm);
        $("#crNormalLimit").html(normal);
    };

    return service;
}

var monitorService = MonitorService();

function GasMonitorService() {
    var service = {};
    //数据的加载
    service.load = function (monitorPointId) {
        var para = service.getParameter();
        gasPollutionController.getPollutionRtdRecords(monitorPointId,1,para.pageSize,para.startTime,para.endTime,para.alarmFlag,function (resp) {
            var data = resp.data;
            service.loadTableData(data);
            var total = resp.extra;
            if(total === 0 ){
                total = 1;
            }
            $("#pageTool").jqPaginator({
                totalPages: Math.ceil(total / para.pageSize),
                visiblePages: 1,
                currentPage: 1,
                prev: '<li><a href="javascript:void(0);" style="background-color: #060f1f"><img src="../../common/images/left.png" style="position: relative;top: 6px;"><\/a><\/li>',
                next: '<li><a href="javascript:void(0);" style="background-color: #060f1f"><img src="../../common/images/right.png" style="position: relative;top: 6px;"><\/a><\/li>',
                page: '<li><a href="javascript:void(0);" style="margin-left:5px;margin-right:5px;background-color: #060f1f"> {{page}} / {{totalPages}} <\/a><\/li>',
                onPageChange: function (pageNo) {
                    pageNumber = pageNo;
                    $(monitorTableGas+" tr:not(:first)").empty("");
                    var p = service.getParameter();
                    gasPollutionController.getPollutionRtdRecords(monitorPointId,pageNo,p.pageSize,p.startTime,p.endTime,p.alarmFlag,function (resp) {
                        service.loadTableData(resp.data);
                    });
                }
            });

        });
    };
    //数据表格的加载
    service.loadTableData = function(tableData){
        tableData.map(function (item,index) {
            //增加颜色的判断，加入td单元格的背景颜色
            var recordDataType = service.getParameter().dataType;
            var $trTemp = $("<tr></tr>");
            $trTemp.append("<td style='width: 33.3%'>"+ common.dateFormatter_hyphen(item.collectTime) +"</td>");
            //0正常 1超标 2异常
            //chromiumAvgAlarmFlag phAvgAlarmFlag nickelAvgAlarmFlag
            switch (item.vocAlarmFlag){
                case 0:
                    $trTemp.append("<td style='width: 33.3%;' onclick=openGasPopup("+"'voc'"+",'"+recordDataType+"'"+",'"+item.id+"'"+")>"+ item.voc +"</td>");
                    break;
                case 1:
                    $trTemp.append("<td style='width: 33.3%;background-color: #f5a623;color: #0C0C0C' onclick=openGasPopup("+"'voc'"+",'"+recordDataType+"'"+",'"+item.id+"'"+")>"+ item.voc +"</td>");
                    break;
                case 2:
                    $trTemp.append("<td style='width:33.3%;background-color: #d0021b;color: #0C0C0C' onclick=openGasPopup("+"'voc'"+",'"+recordDataType+"'"+",'"+item.id+"'"+")>"+ item.voc +"</td>");
                    break;
            }

            switch (item.tolueneAlarmFlag) {
                case 0:
                    $trTemp.append("<td style='width: 33.3%;' onclick=openGasPopup("+"'toluene'"+",'"+recordDataType+"'"+",'"+item.id+"'"+")>"+ item.toluene +"</td>");
                    break;
                case 1:
                    $trTemp.append("<td style='width: 33.3%;background-color: #f5a623;color: #0C0C0C' onclick=openGasPopup("+"'toluene'"+",'"+recordDataType+"'"+",'"+item.id+"'"+")>"+ item.toluene +"</td>");
                    break;
                case 2:
                    $trTemp.append("<td style='width: 33.3%;background-color: #d0021b;color: #0C0C0C' onclick=openGasPopup("+"'toluene'"+",'"+recordDataType+"'"+",'"+item.id+"'"+")>"+ item.toluene +"</td>");
                    break;
            }
            $trTemp.appendTo(monitorTableGas);
        });
    };

    //获取今天的0点是23:59时间
    service.getTodayTime = function () {
        var start = new Date(new Date(new Date().toLocaleDateString()).getTime());
        var end = new Date(new Date(new Date().toLocaleDateString()).getTime()+24*60*60*1000-1);
        return {start:start,end:end};
    };
    //获取load加载所需要的所有参数
    service.getParameter = function () {
        var alarmFlag = $("#sheetAlarmFlag").val();
        var startTime = common.dateFormatter_inverse($("#sheetStartTime").val());
        var endTime = common.dateFormatter_inverse($("#sheetEndTime").val());
        var dataType = $("#sheetDataType").val();
        var pageSize = $("#pageSize").val();
        return {
            alarmFlag:alarmFlag,
            startTime:startTime,
            endTime:endTime,
            dataType:dataType,
            pageSize:pageSize
        }
    };

    //弹窗所需的详细数据项查询
    service.getDataItemDetail = function(dataItemName,recordDataType,recordId){
        gasPollutionController.getDataItemDetail(recordId,dataItemName,function (resp) {
            var data = resp.data;
            service.hiddenAllTable();
            console.log(dataItemName,data);
            switch(dataItemName)
            {
                case 'voc':
                    $("#VocInfo").css('display','block');
                    service.loadVocPopup(data);
                    break;
                case 'toluene':
                    $("#TolueneInfo").css('display','block');
                    service.loadToluenePopup(data);
                    break;
            }
        })
    };

    //加载info弹窗
    service.loadVocPopup = function (data) {
        $("#vocMonitorPointName").html(data.monitorPointName);
        $("#vocCollectTime").html(common.dateFormatter_hyphen(data.collectTime));
        var alarm = data.thresholdConfig.alarmLowerLimit+'-'+data.thresholdConfig.alarmUpperLimit;
        var normal = data.thresholdConfig.normalValueLowerLimit+'-'+data.thresholdConfig.normalValueUpperLimit;
        $("#vocAlarmLimit").html(alarm);
        $("#vocNormalLimit").html(normal);
        $("#vocRtd").html(data.rtd);
    };

    //加载ph弹窗
    service.loadToluenePopup = function (data) {
        $("#tolueneMonitorPointName").html(data.monitorPointName);
        $("#tolueneCollectTime").html(common.dateFormatter_hyphen(data.collectTime));
        var alarm = data.thresholdConfig.alarmLowerLimit+'-'+data.thresholdConfig.alarmUpperLimit;
        var normal = data.thresholdConfig.normalValueLowerLimit+'-'+data.thresholdConfig.normalValueUpperLimit;
        $("#tolueneAlarmLimit").html(alarm);
        $("#tolueneNormalLimit").html(normal);
        $("#tolueneRtd").html(data.rtd);
    };

    //隐藏所有的table
    service.hiddenAllTable = function () {
        $("#info").css('display','none');
        $("#phInfo").css('display','none');
        $("#NiInfo").css('display','none');
        $("#CrInfo").css('display','none');
        $("#VocInfo").css('display','none');
        $("#TolueneInfo").css('display','none');
    };

    return service;
}

var gasMonitorService = GasMonitorService();

//污水初始界面
function sewageInit() {
    //时间的初始化
    dateSelectorInit();

    //首页详情按钮---图标右上方的详情按钮，触发相关的跳转事件
    $(".col-title img").on('click',function () {
       var rightRadioFlag = $(this).attr('id');
       var rightRadio = null;
        /**
         * 1.点击详情按钮，子页面控制父页面的css更改，center增大(80%)，rightmenu隐藏，传入data-id
         * 2.子页面中main中原来的两个row隐藏，取而代之显示一个新的超大div
         * 3.进入radio子界面
         * 4.table子界面可以直接生成？
         */
        //把右侧的radio选中
        switch (rightRadioFlag) {
            case 'phBtn':
                $("input[name='chartRadio']:eq(1)").attr("checked",'checked');
                rightRadio = 'ph';
                break;
            case 'crBtn':
                $("input[name='chartRadio']:eq(2)").attr("checked",'checked');
                rightRadio = 'cr';
                break;
            case 'niBtn':
                $("input[name='chartRadio']:eq(3)").attr("checked",'checked');
                rightRadio = 'ni';
                break;
            case 'pointSpeedBtn':
                $("input[name='chartRadio']:eq(0)").attr("checked",'checked');
                rightRadio = 'sewage';
                break;
        }

        //父页面css大小修改
        var rightMenuWidth =  parent.$(".right").width();
        parent.$(".center").css('width','80%');
        parent.$(".right").hide();
        //console.log(rightMenuWidth);

        //子页面超大div显示
        $(".main").css('display', 'none');
        $(".diagram").css('display', 'block');
        parent.$("#back").attr('hidden',false);//返回上一级按钮显示

        //diagram进行宽度赋值显示
        // $(".chart-right").css('width', rightMenuWidth);
        // var chartLeftWidth = $(".chart").width() - rightMenuWidth -2;
        // $(".chart-left").css('width',chartLeftWidth);
        $(".chart-right").css('width', '20%');
        $(".chart-left").css('width','80%');
        diagramChartInit(rightRadio);
        parent.childRealTimeFlag = 1;
        dataInit2();
    });

    $("#showShBtn").on('click', function () {
        $(".chart").css('display', 'none');
        $(".sheet").css('display', 'block');
        //每次切换之后，时间都重新加载
        dateSelectorInit();
        sheetInit();
    });

    $("#showChartBtn").on('click', function () {
        $(".chart").css('display', 'flex');
        $(".sheet").css('display', 'none');
        //每次切换之后，时间都重新加载
        dateSelectorInit();
        var rightFlag = $("input[name='chartRadio']:checked").val();
        diagramChartInit(rightFlag);
    });

    //加载四个表格
    waterPollutionService.load(parent.monitorPointId);

    //每间隔6s刷新加载四个表格
    setInterval(function () {
        waterPollutionService.load(parent.monitorPointId);
    },60000);

    //chart界面---右键radio切换图表
    $("input[name='chartRadio']").on('change', function () {
        diagramChartInit($(this).val())
    });

    //chart界面--搜索
    $("#chartSearch").on('click', function () {
        var rightFlag = $("input[name='chartRadio']:checked").val();
        diagramChartInit(rightFlag);
    });

}

//大气初始界面
function gasInit() {
    var service = {};
    service.gasInitData = function(){
        var rightFlag = $("input[name='chartRadio']:checked").val();
        switch (rightFlag) {
            case 'sewage':
                rightRadio = 'voc';
                break;
            case 'ph':
                rightRadio = 'toluene';
                break;
        };
        var p = realTimeGasService.getParameterChart();
        // //通过不同的radio加载
        realTimeGasService.loadRadioChart(parent.monitorPointId,p.startTime,p.endTime,p.dataType,rightRadio);
    };

    //时间的初始化
    dateSelectorInit();

    //初始化两个表格的加载
    realTimeGasService.load(parent.monitorPointId);

    var gasInterval = setInterval(function () {
        realTimeGasService.load(parent.monitorPointId);
    },1000);

    //详情按钮的点击
    $(".col-title img").on('click',function () {
        var rightRadioFlag = $(this).attr('id');
        var rightRadio = null;
        /**
         * 1.点击详情按钮，子页面控制父页面的css更改，center增大(80%)，rightmenu隐藏，传入data-id
         * 2.子页面中main中原来的两个row隐藏，取而代之显示一个新的超大div
         * 3.进入radio子界面
         * 4.table子界面可以直接生成？
         */
        //把右侧的radio选中
        switch (rightRadioFlag) {
            case 'phBtn':
                /**
                 * jquery对checked属性的操作存在问题，在这里采用原生的写法
                 * @type {NodeListOf<HTMLElement>}
                 */
                var inputList = document.getElementsByName("chartRadio");
                for(var x=0;x<inputList.length;x++){
                    inputList[x].checked=false;  //取消选中
                }
                var input = document.getElementById("pointRadio");
                input.checked = true;  //选中第二个　

                rightRadio = 'voc';
                break;
            case 'crBtn':
                // $("input[name='chartRadio']:eq(1)").removeAttr("checked");
                // $("input[name='chartRadio']:eq(2)").prop("checked");
                var inputList = document.getElementsByName("chartRadio");
                for(var x=0;x<inputList.length;x++){
                    inputList[x].checked=false;  //取消选中
                }
                var input = document.getElementById("phRadio");
                input.checked = true;  //选中第二个　
                rightRadio = 'toluene';
                break;
        }

        //父页面css大小修改
        var rightMenuWidth =  parent.$(".right").width();
        parent.$(".center").css('width','80%');
        parent.$(".right").hide();
        //console.log(rightMenuWidth);

        //子页面超大div显示
        $(".main").css('display', 'none');
        $(".diagram").css('display', 'block');
        parent.$("#back").attr('hidden',false);//返回上一级按钮显示

        //diagram进行宽度赋值显示
        $(".chart-right").css('width', '20%');
        $(".chart-left").css('width','80%');

        var p = realTimeGasService.getParameterChart();
        // //通过不同的radio加载
        realTimeGasService.loadRadioChart(parent.monitorPointId,p.startTime,p.endTime,p.dataType,rightRadio);
        parent.childRealTimeFlag = 1;
        dataInit2();
        clearInterval(gasInterval);
    });

    //tab切换
    $("#showShBtn").on('click', function () {
        $(".chart").css('display', 'none');
        $(".sheet").css('display', 'block');
        //每次切换之后，时间都重新加载
        dateSelectorInit();
        $(monitorTableGas).css('display','table');
        $(monitorTable).css('display','none');
        sheetGasInit();
    });

    //tab切换
    $("#showChartBtn").on('click', function () {
        $(".chart").css('display', 'flex');
        $(".sheet").css('display', 'none');
        //每次切换之后，时间都重新加载
        dateSelectorInit();
        service.gasInitData();
    });

    //chart界面---右键radio切换图表
    $("input[name='chartRadio']").on('change', function () {
        service.gasInitData();
    });

    //chart界面--搜索
    $("#chartSearch").on('click', function () {
        service.gasInitData();
    });
}

//污水相关的表格加载
function sheetInit() {
    //数据加载
    monitorService.load(parent.monitorPointId);
    //分页显示数量的重置
    $("#pageSize").on('change', function () {
        $('#pageTool').jqPaginator('destroy')
        monitorService.load(parent.monitorPointId);
    });

    //搜索功能
    $("#sheetSearch").on('click', function () {
        $('#pageTool').jqPaginator('destroy');
        monitorService.load(parent.monitorPointId);
    });

    //导出
    $("#sheetExport").on('click', function () {
        var para = monitorService.getParameter();
        var url=host+"/environment-protection/water/pollution"+"/interval/record/export";
        var temp = url + "?monitorPointId=" + encodeURIComponent(parent.monitorPointId)+"&pageNo="+ encodeURIComponent(pageNumber);
        if (para.alarmDataType != undefined) {
            temp = temp + "&alarmDataType=" + encodeURIComponent(para.alarmDataType);
        }
        if (para.pageSize != undefined) {
            temp = temp + "&pageSize=" + encodeURIComponent(para.pageSize);
        }
        if (para.startTime != undefined) {
            temp = temp + "&startTime=" + encodeURIComponent(para.startTime);
        }
        if (para.endTime != undefined) {
            temp = temp + "&endTime=" + encodeURIComponent(para.endTime);
        }
        if (para.dataType != undefined) {
            temp = temp + "&dataType=" + encodeURIComponent(para.dataType);
        }
        if (para.alarmFlag != undefined) {
            temp = temp + "&alarmFlag=" + encodeURIComponent(para.alarmFlag);
        }
        window.location.href = temp;
    });
}

//大气相关的表格加载
function sheetGasInit() {
    //时间选择器
    laydate.render({
        elem: '#startTime', //指定元素
        theme: '#060f1f',
        type: 'datetime',
        value:monitorService.getTodayTime().start
    });
    laydate.render({
        elem: '#endTime', //指定元素
        theme: '#060f1f',
        type: 'datetime',
        value:monitorService.getTodayTime().end
    });

    gasMonitorService.load(parent.monitorPointId);

    //分页显示数量的重置
    $("#pageSize").on('change', function () {
        $('#pageTool').jqPaginator('destroy');
        gasMonitorService.load(parent.monitorPointId);
    });

    //搜索功能
    $("#sheetSearch").on('click', function () {
        $('#pageTool').jqPaginator('destroy');
        gasMonitorService.load(parent.monitorPointId);
    });

    //导出数据
    $("#sheetExport").on('click', function () {
        var para =gasMonitorService.getParameter();
        var url=host+"/environment-protection/gas/pollution"+"/rtd/record/export";
        var temp = url + "?monitorPointId=" + encodeURIComponent(parent.monitorPointId)+"&pageNo="+ encodeURIComponent(pageNumber);
        if (para.pageSize != undefined) {
            temp = temp + "&pageSize=" + encodeURIComponent(para.pageSize);
        }
        if (para.startTime != undefined) {
            temp = temp + "&startTime=" + encodeURIComponent(para.startTime);
        }
        if (para.endTime != undefined) {
            temp = temp + "&endTime=" + encodeURIComponent(para.endTime);
        }
        if (para.alarmFlag != undefined) {
            temp = temp + "&alarmFlag=" + encodeURIComponent(para.alarmFlag);
        }
        window.location.href = temp;
    });
}

//加载详情的趋势表格
function diagramChartInit(radioFlag){
    var p = waterPollutionService.getParameterChart();
    //通过不同的radio加载
    waterPollutionService.loadRadioChart(parent.monitorPointId,p.startTime,p.endTime,p.dataType,radioFlag);
}

//时间的初始化
function dateSelectorInit(){
    //时间选择器
    // if(chartStartTime === undefined){
    //     var s = waterPollutionService.getTodayTime().start;
    //     laydate.render({
    //         elem: '#chartStartTime', //指定元素
    //         theme: '#060f1f',
    //         type: 'datetime',
    //         value:s,
    //         done: function(value, date, endDate){
    //             chartStartTime = value;
    //         }
    //     });
    //     chartStartTime = s;
    // }else{
    //     laydate.render({
    //         elem: '#chartStartTime', //指定元素
    //         theme: '#060f1f',
    //         type: 'datetime',
    //         value:chartStartTime,
    //         done: function(value, date, endDate){
    //             chartStartTime = value;
    //         }
    //     });
    // }
    //
    // if(chartEndTime === undefined){
    //     var e = waterPollutionService.getTodayTime().end;
    //     laydate.render({
    //         elem: '#chartEndTime', //指定元素
    //         theme: '#060f1f',
    //         type: 'datetime',
    //         value:waterPollutionService.getTodayTime().end,
    //         done: function(value, date, endDate){
    //             chartEndTime = value;
    //         }
    //     });
    //     chartEndTime = e;
    // }else{
    //     laydate.render({
    //         elem: '#chartEndTime', //指定元素
    //         theme: '#060f1f',
    //         type: 'datetime',
    //         value:chartEndTime,
    //         done: function(value, date, endDate){
    //             console.log(value,date,endDate)
    //             chartEndTime = value;
    //         }
    //     });
    // }
    //
    // if(sheetStartTime === undefined){
    //     var ss = waterPollutionService.getTodayTime().start
    //     //时间选择器
    //     laydate.render({
    //         elem: '#sheetStartTime', //指定元素
    //         theme: '#060f1f',
    //         type: 'datetime',
    //         value:ss,
    //         done: function(value, date, endDate){
    //             sheetStartTime = value;
    //         }
    //     });
    //     sheetStartTime = ss;
    // }else{
    //     laydate.render({
    //         elem: '#chartEndTime', //指定元素
    //         theme: '#060f1f',
    //         type: 'datetime',
    //         value:sheetStartTime,
    //         done: function(value, date, endDate){
    //             sheetStartTime = value;
    //         }
    //     });
    // }
    //
    // if(sheetEndTime === undefined){
    //     var ee= waterPollutionService.getTodayTime().end;
    //     laydate.render({
    //         elem: '#sheetEndTime', //指定元素
    //         theme: '#060f1f',
    //         type: 'datetime',
    //         value:ee,
    //         done: function(value, date, endDate){
    //             sheetEndTime = value;
    //         }
    //     });
    //     sheetEndTime = ee;
    // }else{
    //     laydate.render({
    //         elem: '#sheetEndTime', //指定元素
    //         theme: '#060f1f',
    //         type: 'datetime',
    //         value:sheetEndTime,
    //         done: function(value, date, endDate){
    //             sheetEndTime = value;
    //         }
    //     });
    // }
}

function dataInit2() {
    if(parent.monitorPointId  === '1'){
        var s = waterPollutionService.getTodayTime().start;
        laydate.render({
            elem: '#chartStartTime', //指定元素
            theme: '#060f1f',
            type: 'datetime',
            value:s,
            done: function(value, date, endDate){
                chartStartTime = value;
            }
        });
    }else{
        var s = waterPollutionService.getTodayTime().start;
        laydate.render({
            elem: '#chartStartTime', //指定元素
            theme: '#060f1f',
            type: 'datetime',
            //当前时间前一个小时
            value:new Date(new Date().getTime() - 1 * 60 * 60 * 1000),
            done: function(value, date, endDate){
                chartStartTime = value;
            }
        });
    }

    var e = waterPollutionService.getTodayTime().end;
    laydate.render({
        elem: '#chartEndTime', //指定元素
        theme: '#060f1f',
        type: 'datetime',
        value:waterPollutionService.getTodayTime().end,
        done: function(value, date, endDate){
            chartEndTime = value;
        }
    });
    chartEndTime = e;

    var ss = waterPollutionService.getTodayTime().start;

    //时间选择器
    laydate.render({
        elem: '#sheetStartTime', //指定元素
        theme: '#060f1f',
        type: 'datetime',
        value:ss,
        done: function(value, date, endDate){
            sheetStartTime = value;
        }
    });
    sheetStartTime = ss;

    var ee= waterPollutionService.getTodayTime().end;
    laydate.render({
        elem: '#sheetEndTime', //指定元素
        theme: '#060f1f',
        type: 'datetime',
        value:ee,
        done: function(value, date, endDate){
            sheetEndTime = value;
        }
    });
    sheetEndTime = ee;
}

//打开弹窗
function openPopup(dataItemName,recordDataType,recordId){
    monitorService.getDataItemDetail(dataItemName,recordDataType,recordId);
    $('#code').center();
    $('#goodcover').show();
    $('#code').show();
    //增加mask效果
    parent.$("#leftMenu").addClass('mask');
    parent.$("#rightMenu").addClass('mask');
}

function openGasPopup(dataItemName,recordDataType,recordId){
    //甲苯，没用，id
    gasMonitorService.getDataItemDetail(dataItemName,recordDataType,recordId);

    $('#code').center();
    $('#goodcover').show();
    $('#code').show();
    parent.$("#leftMenu").addClass('mask');
    parent.$("#rightMenu").addClass('mask');
}

$(function () {
    dataInit2();
    if(parent.monitorPointId === '2'){
        //四个表格界面，隐藏掉两个，四个表格变成两个，相关样式和文字进行重新处理
        $(".row:nth-child(2)").attr('hidden', 'hidden');
        $("#firstTitle").html('空气-VOC');
        $("#secondTitle").html('空气-甲苯');

        $(".chart-right-radio:nth-child(3)").attr('hidden', 'hidden');
        $(".chart-right-radio:nth-child(4)").attr('hidden', 'hidden');

        $(".chart-right-radio:nth-child(1) label").html('VOC');
        $(".chart-right-radio:nth-child(2) label").html('甲苯');

        $("#sheetDataType").empty();
        $("#sheetDataType").append("<option selected value='Value'>实时数据</option>");
        $("#chartDataType").empty();
        $("#chartDataType").append("<option selected value='Value'>实时数据</option>");
        //主函数的加载
        gasInit();
    }

    if(parent.monitorPointId === '1'){
        sewageInit();
    }
});
